using UnityEngine;

public class RCC_CreateAudioSource : MonoBehaviour
{
	public static AudioSource NewAudioSource(GameObject go, string audioName, float minDistance, float maxDistance, float volume, AudioClip audioClip, bool loop, bool playNow, bool destroyAfterFinished)
	{
		GameObject gameObject = new GameObject(audioName);
		AudioSource audioSource = gameObject.AddComponent<AudioSource>();
		if ((bool)BackgroundSoundManager.instance)
		{
			audioSource.outputAudioMixerGroup = BackgroundSoundManager.instance.carMixerGroup;
		}
		audioSource.minDistance = minDistance;
		audioSource.maxDistance = maxDistance;
		audioSource.volume = volume;
		audioSource.clip = audioClip;
		audioSource.loop = loop;
		audioSource.spatialBlend = 1f;
		if (playNow)
		{
			gameObject.GetComponent<AudioSource>().Play();
		}
		if (destroyAfterFinished)
		{
			if ((bool)audioClip)
			{
				Object.Destroy(gameObject, audioClip.length);
			}
			else
			{
				Object.Destroy(gameObject);
			}
		}
		if ((bool)go.transform.FindChild("All Audio Sources"))
		{
			gameObject.transform.SetParent(go.transform.FindChild("All Audio Sources"));
		}
		else
		{
			gameObject.transform.SetParent(go.transform, false);
		}
		gameObject.transform.localPosition = Vector3.zero;
		gameObject.transform.localRotation = Quaternion.identity;
		return audioSource;
	}

	public static void NewHighPassFilter(AudioSource source, float freq, int level)
	{
		if (!(source == null))
		{
			AudioHighPassFilter audioHighPassFilter = source.gameObject.AddComponent<AudioHighPassFilter>();
			audioHighPassFilter.cutoffFrequency = freq;
			audioHighPassFilter.highpassResonanceQ = level;
		}
	}
}
